package com.ruoyi.gis.service.impl;

import com.ruoyi.base.domain.BusWarnWarninfo;
import com.ruoyi.base.mapper.BusWarnWarninfoMapper;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.gis.domain.leaderCockpitVo;
import com.ruoyi.gis.mapper.LeaderCockpitMapper;
import com.ruoyi.gis.service.LeaderCockpitService;
import com.ruoyi.system.mapper.SysDictDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class LeaderCockpitServiceImpl implements LeaderCockpitService {
    @Autowired
    private LeaderCockpitMapper leaderCockpitMapper;

    @Autowired
    private BusWarnWarninfoMapper busWarnWarninfoMapper;

    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Override
    public List<Map<String, Object>> getWaterQuality(leaderCockpitVo vo) {
        //河流下的所有子河流
        List<String> riverIDs = new ArrayList<>();
        if (StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            Map<String, Object> riverriverLevelmap = new HashMap<>();
            riverriverLevelmap.put("topRiverId", vo.getRiverId());
            List<Map<String, Object>> riverriverLevellist = leaderCockpitMapper.getRiverDatas(riverriverLevelmap);
            if (riverriverLevellist != null && riverriverLevellist.size() > 0) {
                for (Map<String, Object> data : riverriverLevellist) {
                    Object id = data.get("id");
                    boolean contains = riverIDs.contains(id);
                    if (contains) {

                    } else {
                        riverIDs.add(String.valueOf(id));
                    }
                }
            }
        }
        if (!StringUtils.isNotEmpty(riverIDs) && StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            riverIDs.add(vo.getRiverId());
        }
        if (vo.getRiverId() != null && !"".equals(vo.getRiverId())) {
            boolean contains1 = riverIDs.contains(vo.getRiverId());
            if (contains1) {
            } else {
                riverIDs.add(vo.getRiverId());
            }

        }
        List<Map<String, Object>> mapdatas = new ArrayList<>();

        Map<String, Object> mapdata = new HashMap<>();
        Map<String, Object> hourdatarealTimeDataQuerymap = new HashMap<>();
        hourdatarealTimeDataQuerymap.put("RiverIDs", riverIDs);
        hourdatarealTimeDataQuerymap.put("countyCode", vo.getCountyCode());
        //断面数据
        List<Map<String, Object>> segmentDataList = leaderCockpitMapper.getAutoSegementData(hourdatarealTimeDataQuerymap);
        List<String> segmentIdList = segmentDataList.stream().map(s -> String.valueOf(s.get("id"))).collect(Collectors.toList());
        //获取最近三天时间
        Date currentDay = DateUtils.dateTime("yyyy-MM-dd HH", DateUtils.dateFormat(new Date(), "yyyy-MM-dd HH"));
        Date threeDays = DateUtils.addDay(currentDay, -3);
        //站点的目标级别以及当前水质类别是否超标
        hourdatarealTimeDataQuerymap.put("beginTime", DateUtils.dateFormat(threeDays, "yyyy-MM-dd HH:mm:ss"));
        hourdatarealTimeDataQuerymap.put("endTime", DateUtils.dateFormat(currentDay, "yyyy-MM-dd HH:mm:ss"));
        hourdatarealTimeDataQuerymap.put("isIntegrals", "1");
        hourdatarealTimeDataQuerymap.put("SegmentIDs", segmentIdList);
        List<Map<String, Object>> wholeHourEvaluateDataList =new ArrayList<>();
        if(StringUtils.isNotEmpty(segmentIdList) && segmentIdList.size() > 0){
            wholeHourEvaluateDataList = leaderCockpitMapper.getWholeHourEvaluateData(hourdatarealTimeDataQuerymap);
        }

        Map<String, List<Map<String, Object>>> wholeHourEvaluateDataCollect = wholeHourEvaluateDataList.stream().collect(Collectors.groupingBy(s -> String.valueOf(s.get("SegmentID"))));

        int size = 0;
        int offlinesize = 0;
        if (StringUtils.isNotEmpty(segmentDataList)) {
            size = segmentIdList.size();
        }
        mapdata.put("isAutoSegmentsize", size);//总数量

        //对整四点数据进行分组
        List<Map<String, Object>> retDataList = new ArrayList<>();
        int isOvesize = 0;//超标数量
        int ySize = 0;//1-3类数量

        int size_1 = 0; //一类数量
        int size_2 = 0; //二类数量
        int size_3 = 0; //三类数量
        int IVSize = 0;//4类数量
        int VSize = 0;//5类数量
        int VISize = 0;//劣V类数量
        int wSize = 0;//无类别
        int dbSize = 0;

        for (String segmentCode : wholeHourEvaluateDataCollect.keySet()) {
            //评价结果以及超标因子
            List<Map<String, Object>> hourEvaluateDataList = wholeHourEvaluateDataCollect.get(segmentCode);
            if (StringUtils.isNotEmpty(hourEvaluateDataList)) {
                for (Map<String, Object> hourEvaluateMap : hourEvaluateDataList) {
                    Object segmentId = hourEvaluateMap.get("SegmentID");
                    Object SampleTime = hourEvaluateMap.get("SampleTime");
                    Object qualityLevel = hourEvaluateMap.get("QualityLevel");
                    Object IsOverStandard = hourEvaluateMap.get("isOverStandard");
                    if ("1".equals(String.valueOf(IsOverStandard))) {//超标
                        isOvesize += 1;
                    } else if (Integer.parseInt(String.valueOf(qualityLevel)) > 0) {
                        dbSize += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) <= 3) {
                        ySize += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) == 1) {
                        size_1 += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) == 2) {
                        size_2 += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) == 3) {
                        size_3 += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) == 4) {
                        IVSize += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) == 5) {
                        VSize += 1;
                    }
                    if (Integer.parseInt(String.valueOf(qualityLevel)) > 0 && Integer.parseInt(String.valueOf(qualityLevel)) > 5) {
                        VISize += 1;
                    }
                    break;
                }
            }

        }
        //计算无类别数量
        wSize = size - size_1 - size_2 - size_3 - IVSize - VSize - VISize;
        offlinesize = wSize;
        mapdata.put("offlinesize", offlinesize);//离线数量
        Map<String, Object> 劣Ⅴmap = new HashMap<>();
        Map<String, Object> Ⅳmap = new HashMap<>();
        Map<String, Object> Ⅴmap = new HashMap<>();
        Map<String, Object> map_1 = new HashMap<>();
        Map<String, Object> map_2 = new HashMap<>();
        Map<String, Object> map_3 = new HashMap<>();
        Map<String, Object> wratemap = new HashMap<>();

        String compliancerate = "";//总体达标率
        String yRate = "0";//1-3类占比

        String Rate_1 = "0";//1类占比
        String Rate_2 = "0";//2类占比
        String Rate_3 = "0";//3类占比
        String IVRate = "0";//4类占比
        String VRate = "0";//5类占比
        String VIRate = "0";//劣V类占比
        String wRate = "0";//无类别占比
        if (size > 0) {
            compliancerate = String.format("%.1f", ((float) (dbSize) / (size - Integer.valueOf(wSize)) * 100));
            yRate = String.format("%.1f", ((float) ySize / (size - Integer.valueOf(wSize)) * 100));

            Rate_1 = String.format("%.1f", ((float) size_1 / size) * 100);
            Rate_2 = String.format("%.1f", ((float) size_2 / size) * 100);
            Rate_3 = String.format("%.1f", ((float) size_3 / size) * 100);
            IVRate = String.format("%.1f", ((float) IVSize / size) * 100);
            VRate = String.format("%.1f", ((float) VSize / size) * 100);
            VIRate = String.format("%.1f", ((float) VISize / size) * 100);
            wRate = String.format("%.1f", ((float) wSize / size) * 100);
        }
        if (compliancerate != null && !"".equals(compliancerate) && !"NaN".equals(compliancerate)) {

        } else {
            compliancerate = "";
        }
        if (yRate != null && !"".equals(yRate) && !"NaN".equals(yRate)) {

        } else {
            yRate = "0";
        }
        劣Ⅴmap.put("size", VISize);//数量
        劣Ⅴmap.put("rate", VIRate);//占比
        劣Ⅴmap.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));//总数
        劣Ⅴmap.put("isOvesize", isOvesize);//超标数
        劣Ⅴmap.put("excellentsize", ySize);
        劣Ⅴmap.put("excellent", yRate);
        劣Ⅴmap.put("compliancesize", dbSize);
        劣Ⅴmap.put("offlinesize", mapdata.get("offlinesize"));//离线
        劣Ⅴmap.put("compliancerate", compliancerate);//总体达标率
        劣Ⅴmap.put("type", "劣Ⅴ类");
        劣Ⅴmap.put("xh", "6");


        Ⅳmap.put("size", IVSize);
        Ⅳmap.put("rate", IVRate);
        Ⅳmap.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        Ⅳmap.put("isOvesize", isOvesize);
        Ⅳmap.put("excellentsize", ySize);
        Ⅳmap.put("excellent", yRate);
        Ⅳmap.put("compliancesize", dbSize);
        Ⅳmap.put("offlinesize", mapdata.get("offlinesize"));
        Ⅳmap.put("compliancerate", compliancerate);
        Ⅳmap.put("type", "Ⅳ类");
        Ⅳmap.put("xh", "4");

        Ⅴmap.put("size", VSize);
        Ⅴmap.put("rate", VRate);
        Ⅴmap.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        Ⅴmap.put("isOvesize", isOvesize);
        Ⅴmap.put("excellentsize", ySize);
        Ⅴmap.put("excellent", yRate);
        Ⅴmap.put("compliancesize", dbSize);
        Ⅴmap.put("offlinesize", mapdata.get("offlinesize"));
        Ⅴmap.put("compliancerate", compliancerate);
        Ⅴmap.put("type", "Ⅴ类");
        Ⅴmap.put("xh", "5");

        wratemap.put("size", wSize);
        wratemap.put("rate", wRate);
        wratemap.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        wratemap.put("isOvesize", isOvesize);
        wratemap.put("excellentsize", ySize);
        wratemap.put("excellent", yRate);
        wratemap.put("compliancesize", dbSize);
        wratemap.put("offlinesize", mapdata.get("offlinesize"));
        wratemap.put("compliancerate", compliancerate);
        wratemap.put("type", "无类别");
        wratemap.put("xh", "7");

        map_1.put("size", size_1);
        map_1.put("rate", Rate_1);
        map_1.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        map_1.put("isOvesize", isOvesize);
        map_1.put("excellentsize", ySize);
        map_1.put("excellent", yRate);
        map_1.put("compliancesize", dbSize);
        map_1.put("offlinesize", mapdata.get("offlinesize"));
        map_1.put("compliancerate", compliancerate);
        map_1.put("type", "Ⅰ类");
        map_1.put("xh", "1");

        map_2.put("size", size_2);
        map_2.put("rate", Rate_2);
        map_2.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        map_2.put("isOvesize", isOvesize);
        map_2.put("excellentsize", ySize);
        map_2.put("excellent", yRate);
        map_2.put("compliancesize", dbSize);
        map_2.put("offlinesize", mapdata.get("offlinesize"));
        map_2.put("compliancerate", compliancerate);
        map_2.put("type", "Ⅱ类");
        map_2.put("xh", "2");

        map_3.put("size", size_3);
        map_3.put("rate", Rate_3);
        map_3.put("isAutoSegmentsize", mapdata.get("isAutoSegmentsize"));
        map_3.put("isOvesize", isOvesize);
        map_3.put("excellentsize", ySize);
        map_3.put("excellent", yRate);
        map_3.put("compliancesize", dbSize);
        map_3.put("offlinesize", mapdata.get("offlinesize"));
        map_3.put("compliancerate", compliancerate);
        map_3.put("type", "Ⅲ类");
        map_3.put("xh", "3");


        mapdatas.add(map_1);
        mapdatas.add(map_2);
        mapdatas.add(map_3);

        mapdatas.add(Ⅳmap);
        mapdatas.add(Ⅴmap);
        mapdatas.add(劣Ⅴmap);
        mapdatas.add(wratemap);

        //判断是否百分比是否100%
        //先按照数据排序
        List<Map<String, Object>> sortList = mapdatas.stream().sorted(Comparator.comparing((Map s) -> Double.parseDouble(s.get("rate").toString()))).collect(Collectors.toList());
        double zby = 100;//剩余占比
        int times = 0;
        for (Map<String, Object> maps : sortList) {
            double warnProportion = Double.parseDouble(maps.get("rate").toString());
            int nums = Integer.parseInt(maps.get("size").toString());
            times = times + 1;
            if (times == sortList.size()) {
                //判断
                if (nums == 0) {
                    maps.put("rate", 0);
                } else {
                    maps.put("rate", new BigDecimal(zby).setScale(1, BigDecimal.ROUND_HALF_UP));
                }
            } else {
                zby = zby - warnProportion;
            }
        }
        sortList = sortList.stream().sorted(Comparator.comparing((Map s) -> Double.parseDouble(s.get("xh").toString()))).collect(Collectors.toList());

        return sortList;
    }

    @Override
    public Map<String, Object> getManualWaterQuality(leaderCockpitVo vo) {
        DecimalFormat df = new DecimalFormat("0.0");
        List<String> assessTypeCode = new ArrayList<>();
        if (StringUtils.isNotEmpty(vo.getAssessTypeCode()) && !"null".equals(vo.getAssessTypeCode())) {
            assessTypeCode = Arrays.asList(vo.getAssessTypeCode().split(","));
        }

        //河流下的所有子河流
        List<String> riverIDs = new ArrayList<>();
        if (StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            Map<String, Object> riverriverLevelmap = new HashMap<>();
            riverriverLevelmap.put("topRiverId", vo.getRiverId());
            List<Map<String, Object>> riverriverLevellist = leaderCockpitMapper.getRiverDatas(riverriverLevelmap);
            if (riverriverLevellist != null && riverriverLevellist.size() > 0) {
                for (Map<String, Object> data : riverriverLevellist) {
                    Object id = data.get("id");
                    boolean contains = riverIDs.contains(id);
                    if (contains) {

                    } else {
                        riverIDs.add(String.valueOf(id));
                    }
                }
            }
        }
        if (!StringUtils.isNotEmpty(riverIDs) && StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            riverIDs.add(vo.getRiverId());
        }
        if (vo.getRiverId() != null && !"".equals(vo.getRiverId())) {
            boolean contains1 = riverIDs.contains(vo.getRiverId());
            if (contains1) {
            } else {
                riverIDs.add(vo.getRiverId());
            }
        }

        Map<String, Object> list = new HashMap<>();
        //先查询最新时间
        Map<String, Object> mspso = new HashMap<>();
        mspso.put("assessTypeCode", assessTypeCode);
        mspso.put("RiverIDs", riverIDs);
        mspso.put("countyCode", vo.getCountyCode());

        String maxSampleDate = leaderCockpitMapper.getbasicevaluatedatamaxSampleDate();
        //获取同环比时间
        String tbksData = null;
        String tbjsData = null;
        String hbksData = null;
        String hbjsData = null;
        if (maxSampleDate != null && !"".equals(maxSampleDate)) {

        } else {
            SimpleDateFormat dfse = new SimpleDateFormat("yyyy-MM");
            String format = dfse.format(new Date());
            maxSampleDate = format;
        }
        Map<String, Object> stringObjectMap = DateUtils.OnTheSameMonthRatio(maxSampleDate, maxSampleDate, "yyyy-MM");
        if (stringObjectMap != null && stringObjectMap.size() > 0) {
            tbksData = (String) stringObjectMap.get("tbksData");
            hbksData = (String) stringObjectMap.get("hbksData");
        }
        //查询所有考核断面id
        List<String> isds = new ArrayList<>();
        List<Map<String, Object>> assessTypeSegmentlist = leaderCockpitMapper.getAssessTypeSegmentall(mspso);
        if (assessTypeSegmentlist != null && assessTypeSegmentlist.size() > 0) {
            for (Map<String, Object> datas : assessTypeSegmentlist) {
                Object id = datas.get("id");
                boolean contains = isds.contains(id);
                if (contains) {
                } else {
                    isds.add(String.valueOf(id));
                }
            }
        }
        int size = isds.size();
        list.put("allSize", size);//断面总数量
        list.put("sampleDate", maxSampleDate);//月份
        Integer getmoon = DateUtils.getmoon(maxSampleDate, "yyyy-MM");
        //获取断面id
        List<String> segmentidlist = new ArrayList<>();
        if (assessTypeSegmentlist != null && assessTypeSegmentlist.size() > 0) {
            for (Map<String, Object> data : assessTypeSegmentlist) {
                Object id = data.get("id");
                boolean contains = segmentidlist.contains(id);
                if (contains) {

                } else {
                    segmentidlist.add(String.valueOf(id));
                }
            }
        }

        mspso.put("SampleDate", maxSampleDate);//最新时间
        mspso.put("SegmentIDs", segmentidlist);//断面id
        mspso.put("assessTypeCode", assessTypeCode);//断面id
        int size1 = segmentidlist.size();
        if (segmentidlist != null && segmentidlist.size() > 0) {
            mspso.put("IsOver", null);//断面id
            Map<String, Object> getbasicevaluatedataIsOverSegmentListall = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspso);
            if (getbasicevaluatedataIsOverSegmentListall != null && getbasicevaluatedataIsOverSegmentListall.size() > 0) {
                Object sizesl = getbasicevaluatedataIsOverSegmentListall.get("sizesl");//数量
                Object isOver = getbasicevaluatedataIsOverSegmentListall.get("IsOver");//状态 0达标 1超标
                list.put("dataSize", sizesl);//存在检测数据数量
            }
            mspso.put("assessTypeCode", assessTypeCode);//考核类型
            Integer dataSize = 0;
            Object dataSize1 = list.get("dataSize");
            if (dataSize1 != null && !"".equals(dataSize1)) {
                dataSize = Integer.valueOf(String.valueOf(dataSize1));
            }
            Integer gksize = size1;
            Map<String, Object> gkgetbasicevaluatedataIsOverSegmentListall = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspso);
            if (gkgetbasicevaluatedataIsOverSegmentListall != null && gkgetbasicevaluatedataIsOverSegmentListall.size() > 0) {
                Object sizesl = gkgetbasicevaluatedataIsOverSegmentListall.get("sizesl");//数量
                Object isOver = gkgetbasicevaluatedataIsOverSegmentListall.get("IsOver");//状态 0达标 1超标
            }
            Map<String, Object> allstringObjectMap = this.getisoverSegment(gksize, assessTypeCode, maxSampleDate, segmentidlist, "0", null);
            list.put("isoverList", allstringObjectMap);
            //优良 和每个水质级别占比/数量
            List<Map<String, Object>> yllist = new ArrayList<>();
            Map<String, Object> ylmap = new HashMap<>();
            ylmap.put("SampleDate", maxSampleDate);//最新时间
            ylmap.put("SegmentIDs", segmentidlist);//断面id
            ylmap.put("assessTypeCode", assessTypeCode);//断面id
            ylmap.put("RiverIDs", riverIDs);
            ylmap.put("countyCode", vo.getCountyCode());
            List<Map<String, Object>> getbasicevaluatedataylSegmentList = leaderCockpitMapper.getbasicevaluatedataylSegment(ylmap);
            //总数量
            Integer allylsize = 0;
            //一类水数量
            Integer onesize = 0;
            //二类水数量
            Integer twosize = 0;
            //三类水数量
            Integer threesize = 0;
            //四类水数量
            Integer foursize = 0;
            //五类水数量
            Integer wsize = 0;
            //劣五类水数量
            Integer lwsize = 0;
            //优良数量
            Integer ylsize = 0;
            //无类别/无数据
            Integer wlsize = 0;
            if (getbasicevaluatedataylSegmentList != null && getbasicevaluatedataylSegmentList.size() > 0) {
                for (Map<String, Object> daat : getbasicevaluatedataylSegmentList) {
                    Object sizesl = daat.get("sizesl");//数量
                    Object qualityLevel = daat.get("QualityLevel");//水质级别
                    Object qualityLevelName = daat.get("QualityLevelName");
                    if (sizesl != null && !"".equals(sizesl)) {
                        if (qualityLevel != null && "0".equals(String.valueOf(qualityLevel))) {
                            wlsize = Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "1".equals(String.valueOf(qualityLevel))) {
                            onesize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "2".equals(String.valueOf(qualityLevel))) {
                            twosize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "3".equals(String.valueOf(qualityLevel))) {
                            threesize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "4".equals(String.valueOf(qualityLevel))) {
                            foursize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "5".equals(String.valueOf(qualityLevel))) {
                            wsize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        } else if (qualityLevel != null && "6".equals(String.valueOf(qualityLevel))) {
                            lwsize = Integer.valueOf(String.valueOf(sizesl));
                            allylsize = allylsize + Integer.valueOf(String.valueOf(sizesl));
                        }

                    }
                }
            }
            //数量处理完成后进行数据处理
            ylsize = onesize + twosize + threesize;
            //(达标人数/总人数)×100%
            double yl = 0;
            if (0 != ylsize && dataSize > 0) {
                int i = size - dataSize;
                yl = (Double.valueOf(ylsize) / Double.valueOf(dataSize)) * 100;
            }
            list.put("yl", df.format(yl));
            list.put("ylsize", ylsize);
            Map<String, Object> wlmaps = new HashMap<>();
            //(达标人数/总人数)×100%
            int si = size - allylsize;
            wlsize = wlsize + si;
            double wlyl = 0;
            if (wlsize != 0) {
                wlyl = (Double.valueOf(wlsize) / Double.valueOf(size)) * 100;
            }
            wlmaps.put("ylsize", wlsize);
            wlmaps.put("ylzb", df.format(wlyl));
            wlmaps.put("qualityLevel", "0");
            wlmaps.put("qualityLevelpx", "99");
            wlmaps.put("qualityLevelName", "无类别");
            yllist.add(wlmaps);
            Map<String, Object> onew = this.getylSegment(size, Integer.valueOf(String.valueOf(onesize)), String.valueOf(1), String.valueOf("Ⅰ类"));
            yllist.add(onew);
            Map<String, Object> twow = this.getylSegment(size, Integer.valueOf(String.valueOf(twosize)), String.valueOf(2), String.valueOf("Ⅱ类"));
            yllist.add(twow);
            Map<String, Object> threew = this.getylSegment(size, Integer.valueOf(String.valueOf(threesize)), String.valueOf(3), String.valueOf("Ⅲ类"));
            yllist.add(threew);
            Map<String, Object> fourw = this.getylSegment(size, Integer.valueOf(String.valueOf(foursize)), String.valueOf(4), String.valueOf("Ⅳ类"));
            yllist.add(fourw);
            Map<String, Object> ww = this.getylSegment(size, Integer.valueOf(String.valueOf(wsize)), String.valueOf(5), String.valueOf("Ⅴ类"));
            yllist.add(ww);
            Map<String, Object> lwsizew = this.getylSegment(size, Integer.valueOf(String.valueOf(lwsize)), String.valueOf(6), String.valueOf("劣Ⅴ类"));
            yllist.add(lwsizew);
            //优良同环比计算
            Map<String, Object> ylstringObjectMaps = this.allgetylSegment(size, assessTypeCode, maxSampleDate, segmentidlist, null);
            if (ylstringObjectMaps != null && ylstringObjectMaps.size() > 0) {
                allstringObjectMap.put("ylsize", ylstringObjectMaps.get("ylsize"));
                allstringObjectMap.put("tbylsize", ylstringObjectMaps.get("tbylsize"));
                allstringObjectMap.put("hbylsize", ylstringObjectMaps.get("hbylsize"));
                allstringObjectMap.put("yl", ylstringObjectMaps.get("yl"));
                allstringObjectMap.put("tbyl", ylstringObjectMaps.get("tbyl"));
                allstringObjectMap.put("hbyl", ylstringObjectMaps.get("hbyl"));
                allstringObjectMap.put("yltbdataStatus", ylstringObjectMaps.get("yltbdataStatus"));
                allstringObjectMap.put("yltbdataStatusName", ylstringObjectMaps.get("yltbdataStatusName"));
                allstringObjectMap.put("yltbdataStatusdata", ylstringObjectMaps.get("yltbdataStatusdata"));
                allstringObjectMap.put("ylhbdataStatus", ylstringObjectMaps.get("ylhbdataStatus"));
                allstringObjectMap.put("ylhbdataStatusName", ylstringObjectMaps.get("ylhbdataStatusName"));
                allstringObjectMap.put("ylhbdataStatusdata", ylstringObjectMaps.get("ylhbdataStatusdata"));
                allstringObjectMap.put("yldataTime", ylstringObjectMaps.get("yldataTime"));
                allstringObjectMap.put("ylallSize", ylstringObjectMaps.get("ylallSize"));
                allstringObjectMap.put("yltbdataTime", ylstringObjectMaps.get("yltbdataTime"));
                allstringObjectMap.put("ylhbdataTime", ylstringObjectMaps.get("ylhbdataTime"));

            }

            list.put("isoverList", allstringObjectMap);
            //判断是否百分比是否100%
            //先按照数据排序
            List<Map<String, Object>> sortList = yllist.stream().sorted(Comparator.comparing((Map s) -> Double.parseDouble(s.get("ylzb").toString()))).collect(Collectors.toList());
            double zby = 100;//剩余占比
            int times = 0;
            for (Map<String, Object> maps : sortList) {
                double warnProportion = Double.parseDouble(maps.get("ylzb").toString());
                int nums = Integer.parseInt(maps.get("ylsize").toString());
                times = times + 1;
                if (times == sortList.size()) {
                    //判断
                    if (nums == 0) {
                        maps.put("ylzb", 0);
                    } else {
                        //注释多余处理，导致小数位数不一致
                        //maps.put("ylzb",new BigDecimal(zby).setScale(1,BigDecimal.ROUND_HALF_UP));
                    }
                } else {
                    zby = zby - warnProportion;
                }
            }
            sortList = sortList.stream().sorted(Comparator.comparing((Map s) -> Double.parseDouble(s.get("qualityLevelpx").toString()))).collect(Collectors.toList());

            list.put("list", sortList);
        }
        return list;
    }

    @Override
    public Map<String, Object> getManualSegmentDateChange(leaderCockpitVo vo) {
        DecimalFormat df = new DecimalFormat("0.0");
        Map<String, Object> list = new HashMap<>();
//河流下的所有子河流
        List<String> riverIDs = new ArrayList<>();
        if (StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            Map<String, Object> riverriverLevelmap = new HashMap<>();
            riverriverLevelmap.put("topRiverId", vo.getRiverId());
            List<Map<String, Object>> riverriverLevellist = leaderCockpitMapper.getRiverDatas(riverriverLevelmap);
            if (riverriverLevellist != null && riverriverLevellist.size() > 0) {
                for (Map<String, Object> data : riverriverLevellist) {
                    Object id = data.get("ID");
                    boolean contains = riverIDs.contains(id);
                    if (contains) {

                    } else {
                        riverIDs.add(String.valueOf(id));
                    }
                }
            }
        }
        if (!StringUtils.isNotEmpty(riverIDs) && StringUtils.isNotEmpty(vo.getRiverId()) && !"null".equals(vo.getRiverId())) {
            riverIDs.add(vo.getRiverId());
        }
        if (vo.getRiverId() != null && !"".equals(vo.getRiverId())) {
            boolean contains1 = riverIDs.contains(vo.getRiverId());
            if (contains1) {
            } else {
                riverIDs.add(vo.getRiverId());
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("RiverIDs", riverIDs);
        map.put("countyCode", vo.getCountyCode());
        //查询所有考核断面id
        List<Map<String, Object>> assessTypeSegmentlist = leaderCockpitMapper.getAssessTypeSegmentall(map);

        List<String> Segmentidse = new ArrayList<>();
        if (assessTypeSegmentlist != null && !"".equals(assessTypeSegmentlist)) {
            for (Map<String, Object> das : assessTypeSegmentlist) {
                Object id = das.get("id");
                boolean contains = Segmentidse.contains(id);
                if (contains) {
                } else {
                    Segmentidse.add(String.valueOf(id));
                }
            }
        }
        int size = Segmentidse.size();
        //先查询最新时间
        String maxSampleDate = leaderCockpitMapper.getbasicevaluatedatamaxSampleDate();
        String SampleDate = maxSampleDate + "-01 00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        map.put("SampleDate", SampleDate);
        List<Map<String, Object>> trendOfChangeSegment = leaderCockpitMapper.getTrendOfChangeSegment(map);
        List<Map<String, Object>> getTrendOfChangeSegmentisover = leaderCockpitMapper.getTrendOfChangeSegmentisover(map);

        List<String> timeList = new ArrayList<>();
        List<String> levelList = new ArrayList<>();
        levelList.add("1");
        levelList.add("2");
        levelList.add("3");
        levelList.add("4");
        levelList.add("5");
        levelList.add("6");
        List<Map<String, Object>> data = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            Map<String, Object> mapsdat = new HashMap<>();
            Integer wlsiez = 0;//无类数量
            Integer ylsiez = 0;//优良数量
            BigDecimal zbsiez = new BigDecimal(100);//占比
            String format = null;
            if (maxSampleDate != null && !"".equals(maxSampleDate)) {
                if (i == 0) {
                    format = maxSampleDate;
                } else {
                    Calendar calendar = Calendar.getInstance();
                    Date parse = null;

                    try {
                        parse = sdf.parse(maxSampleDate);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    calendar.setTime(parse);

                    // 添加 -1 小时到当前时间
                    calendar.add(Calendar.MONTH, -i);
                    Date time = calendar.getTime();
                    format = sdf.format(time);
                }
            } else {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.MONTH, -i);
                Date time = calendar.getTime();
                format = sdf.format(time);
            }
            timeList.add(format);
            map.put("SampleDate", format);
            mapsdat.put("month", format);

            //根据上面获取对应的时间
            if (trendOfChangeSegment != null && trendOfChangeSegment.size() > 0) {
                //根据时间分组
                Map<String, List<Map<String, Object>>> sunmapsSegmentID =
                        trendOfChangeSegment.stream().collect(
                                Collectors.groupingBy(item -> item.get("monSampleDate").toString())
                        );
                Map<String, List<Map<String, Object>>> isoversunmapsSegmentID =
                        getTrendOfChangeSegmentisover.stream().collect(
                                Collectors.groupingBy(item -> item.get("monSampleDate").toString())
                        );
                List<Map<String, Object>> mapList = sunmapsSegmentID.get(format);//各水质类别数量
                List<Map<String, Object>> isovermapList = isoversunmapsSegmentID.get(format);//正常的数量
                for (String level : levelList) {
                    List<Map<String, Object>> qualityLevelList = new ArrayList<>();
                    if (StringUtils.isNotEmpty(mapList) && mapList.size() > 0) {
                        qualityLevelList = mapList.stream().filter(item -> String.valueOf(item.get("QualityLevel")).equals(level)).collect(Collectors.toList());
                    }
                    Object sizesl = null;
                    BigDecimal bd = new BigDecimal(0);
                    if (StringUtils.isNotEmpty(qualityLevelList) && qualityLevelList.size() > 0) {
                        sizesl = qualityLevelList.get(0).get("sizesl");
                        Integer integer = Integer.valueOf(String.valueOf(sizesl));
                        wlsiez = wlsiez + integer;
                        ylsiez = ylsiez + integer;
                        //优秀的个体÷总体×100%
                        double v = (Double.valueOf(integer) / Double.valueOf(size)) * 100;
                        bd = BigDecimal.valueOf(v).setScale(1, RoundingMode.HALF_UP);

                        zbsiez = zbsiez.subtract(bd);
                    }

                    if ("1".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("oneCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("oneCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("oneCategoryszie", sizesl);
                    }
                    if ("2".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("twoCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("twoCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("twoCategoryszie", sizesl);
                    }
                    if ("3".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("threeCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("threeCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("threeCategoryszie", sizesl);
                    }
                    if ("4".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("fourCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("fourCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("fourCategoryszie", sizesl);
                    }
                    if ("5".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("fiveCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("fiveCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("fiveCategoryszie", sizesl);
                    }
                    if ("6".equals(level)) {
                        int i1 = size - wlsiez;
                        if (i1 > 0) {
                            mapsdat.put("sixCategory", String.valueOf(bd));
                        } else {
                            mapsdat.put("sixCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                        }
                        mapsdat.put("sixCategoryszie", sizesl);
                    }
                }

                //优秀的个体÷总体×100%
                if (wlsiez > 0) {
                    int i1 = size - wlsiez;
                    double v = (Double.valueOf(i1) / Double.valueOf(size)) * 100;
                    double v1 = (Double.valueOf(wlsiez) / Double.valueOf(size)) * 100;
                    if (i1 > 0) {
                        mapsdat.put("wuCategory", String.valueOf(zbsiez.setScale(1, BigDecimal.ROUND_HALF_UP)));
                    } else {
                        mapsdat.put("wuCategory", df.format(v));
                    }
                    mapsdat.put("wuCategorysize", i1);
                } else {
                    mapsdat.put("wuCategory", 0);
                    mapsdat.put("wuCategorysize", wlsiez);
                }
                if (ylsiez > 0) {
                    int i1 = 0;
                    Object wuCategorysize = mapsdat.get("wuCategorysize");
                    if (wuCategorysize != null && !"".equals(wuCategorysize)) {
                        Integer integer = Integer.valueOf(String.valueOf(wuCategorysize));
                        i1 = integer;
                    }
                    double v = (Double.valueOf(ylsiez) / Double.valueOf(size - i1)) * 100;
                    BigDecimal bd = BigDecimal.valueOf(v).setScale(1, RoundingMode.DOWN);
                    mapsdat.put("ylsize", ylsiez);
                    mapsdat.put("ylCategory", df.format(v));
                } else {
                    mapsdat.put("ylsize", ylsiez);
                    mapsdat.put("ylCategory", 0);
                }
                //判断是否百分比是否100%
                //先按照数据排序
                double zby = 100;//剩余占比
                int times = 0;
                if (isovermapList != null && isovermapList.size() > 0) {
                    for (Map<String, Object> datalist : isovermapList) {
                        Object sizesl = datalist.get("sizesl");//数量
                        if (sizesl != null && !"".equals(sizesl)) {
                            int i1 = 0;
                            Object wuCategorysize = mapsdat.get("wuCategorysize");
                            if (wuCategorysize != null && !"".equals(wuCategorysize)) {
                                Integer integer = Integer.valueOf(String.valueOf(wuCategorysize));
                                i1 = integer;
                            }
                            Integer integer = Integer.valueOf(String.valueOf(sizesl));
                            //优秀的个体÷总体×100%
                            double v = (Double.valueOf(integer) / Double.valueOf(size - i1)) * 100;
                            mapsdat.put("isoversize", integer);
                            mapsdat.put("isover", df.format(v));
                        }

                    }
                }
            }
            data.add(mapsdat);
        }
        list.put("timeList", timeList);
        list.put("data", data);
        return list;
    }

    @Override
    public List<BusWarnWarninfo> getWarningLastInfo(leaderCockpitVo vo) {
        //获取最新的预警时间

        String maxWarnTime = leaderCockpitMapper.getMaxWarnTime();
        if (!StringUtils.isNotEmpty(maxWarnTime)) {
            maxWarnTime = DateUtils.dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss");
        }
        BusWarnWarninfo busWarnWarninfo = new BusWarnWarninfo();
        busWarnWarninfo.setBeginTime(DateUtils.dateFormat(DateUtils.addDays(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", maxWarnTime), -1), "yyyy-MM-dd 00:00:00"));
        busWarnWarninfo.setEndTime(maxWarnTime);
        List<BusWarnWarninfo> list = busWarnWarninfoMapper.selectBusWarnWarninfoList(busWarnWarninfo);
        //查询最新的预警数据
        return list;
    }

    @Override
    public Map<String, Object> getWarningStatistics(leaderCockpitVo vo) {
        Map<String, Object> map=new HashMap<>();
        //当天时间
        vo.setBeginTime(DateUtils.dateFormat(new Date(), "yyyy-MM-dd 00:00:00"));
        vo.setEndTime(DateUtils.dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
//类型下所有预警类型
        SysDictData dictData = new SysDictData();
        dictData.setDictType("warn_class_type");
        dictData.setStatus("0");
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataList(dictData);
        List<Map<String, Object>> warnDataInfoList = new ArrayList<>();
        for (SysDictData sysDictData : sysDictDataList) {
            Map<String, Object> retMap=new HashMap<>();
            String dictValue = sysDictData.getDictValue();
            vo.setWarnCategory(dictValue);
            List<Map<String, Object>> warnDataInfo = leaderCockpitMapper.getWarnProcessingState(vo);
            int numbers = 0;
            if(StringUtils.isEmpty(warnDataInfo) && warnDataInfo.size()>0){
                numbers=Integer.parseInt(String.valueOf(warnDataInfo.get(0).get("numbers")));
            }
            retMap.put("type",dictValue);
            retMap.put("typeName",sysDictData.getDictLabel());
            retMap.put("nums",numbers);
            warnDataInfoList.add(retMap);
        }
        map.put("warnDataInfoList",warnDataInfoList);
        //按照预警等级统计
        List<Map<String, Object>> warnDatas = leaderCockpitMapper.getWarnLevelData(vo);

        Map<String, List<Map<String, Object>>> wqDataWarnCollect = warnDatas.stream().collect(Collectors.groupingBy(s->String.valueOf(s.get("WarnLevel"))));
        int totalNums = 0;
        if (StringUtils.isNotEmpty(warnDatas)) {
            for (Map<String, Object> levelMap : warnDatas) {
                totalNums = totalNums + Integer.parseInt(String.valueOf(levelMap.get("numbers")));
            }
        }
        List<Map<String, String>> warnRankList = getWarnRankData();
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (Map<String, String> levelMap : warnRankList) {
            Map<String, Object> warnmap = new LinkedHashMap<>();
            warnmap.put("warnLevel", levelMap.get("code"));
            warnmap.put("warnLevelName", levelMap.get("name"));
            List<Map<String, Object>> warninfoList = wqDataWarnCollect.get(levelMap.get("code"));
            int nums = 0;
            if (StringUtils.isNotEmpty(warninfoList)) {
                for (Map<String, Object> warninfo : warninfoList) {
                    nums = nums +Integer.parseInt(String.valueOf(levelMap.get("numbers")));
                }
            }

            warnmap.put("number", nums);
            mapList.add(warnmap);
        }
        map.put("warnDataLevelList",mapList);
        map.put("sampleTime",DateUtils.dateFormat(new Date(),"yyyy-MM-dd"));
        map.put("totalNums", totalNums);
        return map;
    }

    @Override
    public Map<String, Object> getPollutionSourceAnalysis(leaderCockpitVo vo) {
        Map<String, Object> map = new HashMap<>();
        //当天时间
        vo.setBeginTime(DateUtils.dateFormat(new Date(), "yyyy-MM-dd 00:00:00"));
        vo.setEndTime(DateUtils.dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));

        //查询污染源企业数量和污水处理厂数量
       Map<String,Object> pollutionMap=leaderCockpitMapper.getPollutionMap(vo);
        //入河排污口数量
        int outfallNums = leaderCockpitMapper.getOutfallNums(vo);
        //当日排放量和超标企业
        List<Map<String,Object>> overPollutionList=leaderCockpitMapper.cbpollutionsourceDatasize(vo);
        int overPollutionNums=0;
        if(StringUtils.isNotEmpty(overPollutionList) && overPollutionList.size()>0){
            overPollutionNums=overPollutionList.size();
        }
        List<Map<String,Object>> pollutionsourceneFlowList=leaderCockpitMapper.pollutionsourceneFlow(vo);
        BigDecimal discharge=new BigDecimal(0);
        if(pollutionsourceneFlowList!=null && pollutionsourceneFlowList.size()>0){
            discharge=new BigDecimal(String.valueOf(pollutionsourceneFlowList.get(0).get("couFlow"))).divide(new BigDecimal(1000),2,BigDecimal.ROUND_HALF_UP);
        }
        //近半个月每日排放量和超标企业
        vo.setBeginTime(DateUtils.dateFormat(DateUtils.addDay(new Date(),-15), "yyyy-MM-dd"));
        vo.setEndTime(DateUtils.dateFormat(new Date(), "yyyy-MM-dd"));
        List<Map<String,Object>> overPollutionDatas=leaderCockpitMapper.overPollutionsourceDatasize(vo);
        List<Map<String,Object>> pollutionsourceneFlowDatas=leaderCockpitMapper.pollutionsourceneFlow(vo);
      List<String>  dateList=DateUtils.getdayBetweenDate(vo.getBeginTime(), vo.getEndTime());
      List<Map<String,Object>> retList=new ArrayList<>();
      for(String date:dateList){
          Map<String,Object> retMap=new HashMap<>();
          retMap.put("dateTime",date);
          List<Map<String,Object>> overPollutionData= overPollutionDatas.stream().filter(s->date.equals(String.valueOf(s.get("daymonitorTime")))).collect(Collectors.toList());
          List<Map<String,Object>> pollutionsourceneFlowData=pollutionsourceneFlowDatas.stream().filter(s->date.equals(String.valueOf(s.get("daymonitorTime")))).collect(Collectors.toList());
          BigDecimal flowValue=new BigDecimal(0);
          int overNums=0;
        if(StringUtils.isNotEmpty(pollutionsourceneFlowData) && pollutionsourceneFlowData.size()>0){
            flowValue=new BigDecimal(String.valueOf(pollutionsourceneFlowData.get(0).get("couFlow"))).divide(new BigDecimal(1000),2,BigDecimal.ROUND_HALF_UP);
          }
          if(StringUtils.isNotEmpty(overPollutionData) && overPollutionData.size()>0){
              overNums=Integer.parseInt(String.valueOf(overPollutionData.get(0).get("size")));
          }
          retMap.put("discharge",flowValue);
          retMap.put("overNums",overNums);
          retList.add(retMap);
      }


        //污染源企业
        map.put("pollutionNums",pollutionMap.get("pollutionNums"));
        //污水处理厂
        map.put("sewagefarmNums",pollutionMap.get("sewagefarmNums"));
        //入河排污口
        map.put("outfallNums",outfallNums);
        //当日排放量
        map.put("discharge",discharge);
        //当日超标企业
        map.put("overNums",overPollutionNums);
        //近半个月排放量和超标企业
        map.put("pollutionList",retList);
        return map;
    }

    /**
     * 查询达标率
     *
     * @Param [size 总数量, assessTypeCode 考核类型, dataTime 时间, segmentidlist 断面id, isover 是否达标 0达标 1未达标]
     **/
    public Map<String, Object> getisoverSegment(Integer size, List<String> assessTypeCode, String dataTime, List<String> segmentidlist, String isover, String accumulated) {
        DecimalFormat df = new DecimalFormat("0.0");
        Map<String, Object> mspso = new HashMap<>();
        Map<String, Object> list = new HashMap<>();
        mspso.put("SampleDate", dataTime);//最新时间
        mspso.put("SegmentIDs", segmentidlist);//断面id
        mspso.put("assessTypeCode", assessTypeCode);//断面id
        mspso.put("IsOver", isover);//断面id
        Map<String, Object> mspsoall = new HashMap<>();
        mspsoall.put("SampleDate", dataTime);//最新时间
        mspsoall.put("SegmentIDs", segmentidlist);//断面id
        mspsoall.put("assessTypeCode", assessTypeCode);//断面id
        //获取同环比时间
        String tbksData = null;
        String tbjsData = null;
        String hbksData = null;
        String hbjsData = null;
        Map<String, Object> stringObjectMap = DateUtils.OnTheSameMonthRatio(dataTime, dataTime, "yyyy-MM");
        if (stringObjectMap != null && stringObjectMap.size() > 0) {
            tbksData = (String) stringObjectMap.get("tbksData");
            hbksData = (String) stringObjectMap.get("hbksData");
        }
        //查询达标次数
        Integer IsOversize = 0;
        Integer IsOversizeall = 0;
        Map<String, Object> getbasicevaluatedataIsOverSegmentList = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspso);
        Map<String, Object> getbasicevaluatedataIsOverSegmentListall = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspsoall);

        if (getbasicevaluatedataIsOverSegmentListall != null && getbasicevaluatedataIsOverSegmentListall.size() > 0) {
            Object sizesl = getbasicevaluatedataIsOverSegmentListall.get("sizesl");//数量
            Object isOver = getbasicevaluatedataIsOverSegmentListall.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                IsOversizeall = IsOversizeall + integer;
            }
        }
        if (getbasicevaluatedataIsOverSegmentList != null && getbasicevaluatedataIsOverSegmentList.size() > 0) {
            Object sizesl = getbasicevaluatedataIsOverSegmentList.get("sizesl");//数量
            Object isOver = getbasicevaluatedataIsOverSegmentList.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                IsOversize = integer;
            }
        }

        //同比
        mspso.put("SampleDate", tbksData);//最新时间
        mspsoall.put("SampleDate", tbksData);//最新时间
        mspso.put("IsOver", isover);//断面id
        //查询达标次数
        Integer tbIsOversize = 0;
        Integer tbIsOversizeall = 0;
        Map<String, Object> tbgetbasicevaluatedataIsOverSegmentList = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspso);
        Map<String, Object> tbgetbasicevaluatedataIsOverSegmentListall = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspsoall);
        if (tbgetbasicevaluatedataIsOverSegmentList != null && tbgetbasicevaluatedataIsOverSegmentList.size() > 0) {
            Object sizesl = tbgetbasicevaluatedataIsOverSegmentList.get("sizesl");//数量
            Object isOver = tbgetbasicevaluatedataIsOverSegmentList.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                tbIsOversize = integer;
            }
        }
        if (tbgetbasicevaluatedataIsOverSegmentListall != null && tbgetbasicevaluatedataIsOverSegmentListall.size() > 0) {
            Object sizesl = tbgetbasicevaluatedataIsOverSegmentListall.get("sizesl");//数量
            Object isOver = tbgetbasicevaluatedataIsOverSegmentListall.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                tbIsOversizeall = tbIsOversizeall + integer;
            }
        }
        //环比
        mspso.put("SampleDate", hbksData);//最新时间
        mspsoall.put("SampleDate", hbksData);//最新时间
        mspso.put("IsOver", isover);//断面id
        //查询达标次数
        Integer hbIsOversize = 0;
        Integer hbIsOversizeall = 0;

        Map<String, Object> hbgetbasicevaluatedataIsOverSegmentList = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspso);
        Map<String, Object> hbgetbasicevaluatedataIsOverSegmentListall = leaderCockpitMapper.getbasicevaluatedataIsOverSegment(mspsoall);

        if (hbgetbasicevaluatedataIsOverSegmentList != null && hbgetbasicevaluatedataIsOverSegmentList.size() > 0) {
            Object sizesl = hbgetbasicevaluatedataIsOverSegmentList.get("sizesl");//数量
            Object isOver = hbgetbasicevaluatedataIsOverSegmentList.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                hbIsOversize = integer;
            }
        }
        if (hbgetbasicevaluatedataIsOverSegmentListall != null && hbgetbasicevaluatedataIsOverSegmentListall.size() > 0) {
            Object sizesl = hbgetbasicevaluatedataIsOverSegmentListall.get("sizesl");//数量
            Object isOver = hbgetbasicevaluatedataIsOverSegmentListall.get("IsOver");//状态 0达标 1超标
            if (sizesl != null && !"".equals(sizesl)) {
                Integer integer = Integer.valueOf(String.valueOf(sizesl));
                hbIsOversizeall = hbIsOversizeall + integer;
            }
        }
        //(达标人数/总人数)×100%
        double IsOverv = 0;
        double tbIsOverv = 0;
        double hbIsOverv = 0;
        if (0 != IsOversize) {
            IsOverv = (Double.valueOf(IsOversize) / Double.valueOf(IsOversizeall)) * 100;
        }
        if (0 != tbIsOversize) {
            tbIsOverv = (Double.valueOf(tbIsOversize) / Double.valueOf(tbIsOversizeall)) * 100;
        }
        if (0 != hbIsOversize) {
            hbIsOverv = (Double.valueOf(hbIsOversize) / Double.valueOf(hbIsOversizeall)) * 100;
        }
        List<Map<String, Object>> isoverlist = new ArrayList<>();

        list.put("isOversize", IsOversize);
        list.put("tbisOversize", tbIsOversize);
        list.put("hbisOversize", hbIsOversize);
        list.put("isOver", df.format(IsOverv));
        list.put("tbisOver", df.format(tbIsOverv));
        list.put("hbisOver", df.format(hbIsOverv));
        //tbIsOverv-isOver 同/环比 -当前 大于0就是上升 小于0下降
        // 上升下降 上升1 下降0 2持平
        double tbv = tbIsOverv - IsOverv;
        double hbv = hbIsOverv - IsOverv;

        if (Double.valueOf(tbIsOversize) > 0 && String.valueOf(Double.valueOf(tbIsOversize)).equals(String.valueOf(Double.valueOf(IsOversize)))) {
            list.put("tbdataStatus", "2");
            list.put("tbdataStatusName", "持平");
        } else if (Double.valueOf(tbIsOversize) > 0 && Double.valueOf(IsOversize) < Double.valueOf(tbIsOversize)) {//小于
            list.put("tbdataStatus", "0");
            list.put("tbdataStatusName", "下降");
        } else if (Double.valueOf(tbIsOversize) > 0 && Double.valueOf(IsOversize) > Double.valueOf(tbIsOversize)) {//大于
            list.put("tbdataStatus", "1");
            list.put("tbdataStatusName", "上升");
        } else {
            list.put("tbdataStatus", "");
            list.put("tbdataStatusName", "");
        }
        if (Double.valueOf(hbIsOversize) > 0 && String.valueOf(Double.valueOf(hbIsOversize)).equals(String.valueOf(Double.valueOf(IsOversize)))) {
            list.put("hbdataStatus", "2");
            list.put("hbdataStatusName", "持平");
        } else if (Double.valueOf(hbIsOversize) > 0 && Double.valueOf(IsOversize) < Double.valueOf(hbIsOversize)) {
            list.put("hbdataStatus", "0");
            list.put("hbdataStatusName", "下降");
        } else if (Double.valueOf(hbIsOversize) > 0 && Double.valueOf(IsOversize) > Double.valueOf(hbIsOversize)) {
            list.put("hbdataStatus", "1");
            list.put("hbdataStatusName", "上升");
        } else {
            list.put("hbdataStatus", "");
            list.put("hbdataStatusName", "");
        }
        list.put("tbdataStatusdata", df.format(tbv));

        list.put("hbdataStatusdata", df.format(hbv));
        list.put("dataTime", dataTime);
        list.put("allSize", size);
        list.put("tbdataTime", tbksData);
        list.put("hbdataTime", hbksData);

        return list;
    }

    /**
     * 优良计算
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [size 总数量, sizes 水质级别数量, qualityLevel 水质级别]
     **/
    public Map<String, Object> getylSegment(Integer size, Integer sizes, String qualityLevel, String qualityLevelName) {
        DecimalFormat df = new DecimalFormat("0.0");
        Map<String, Object> list = new HashMap<>();
        //(达标人数/总人数)×100%
        list.put("ylsize", sizes);
        double yl = 0;
        if (sizes != 0) {
            yl = (Double.valueOf(sizes) / Double.valueOf(size)) * 100;
        }
        list.put("ylzb", df.format(yl));
        list.put("qualityLevel", qualityLevel);
        list.put("qualityLevelpx", qualityLevel);
        list.put("qualityLevelName", qualityLevelName);

        return list;
    }

    /**
     * 8
     *
     * @Param [size, assessTypeCode, dataTime, segmentidlist, isover, accumulated]
     **/
    public Map<String, Object> allgetylSegment(Integer size, List<String> assessTypeCode, String dataTime, List<String> segmentidlist, String accumulated) {
        DecimalFormat df = new DecimalFormat("0.0");
        Map<String, Object> mspso = new HashMap<>();
        Map<String, Object> list = new HashMap<>();

        mspso.put("SampleDate", dataTime);//最新时间
        mspso.put("SegmentIDs", segmentidlist);//断面id
        mspso.put("assessTypeCode", assessTypeCode);//断面id
        //获取同环比时间
        String tbksData = null;
        String tbjsData = null;
        String hbksData = null;
        String hbjsData = null;
        Map<String, Object> stringObjectMap = DateUtils.OnTheSameMonthRatio(dataTime, dataTime, "yyyy-MM");
        if (stringObjectMap != null && stringObjectMap.size() > 0) {
            tbksData = (String) stringObjectMap.get("tbksData");
            hbksData = (String) stringObjectMap.get("hbksData");
        }
        //查询优良数量
        List<Map<String, Object>> mapList = leaderCockpitMapper.getbasicevaluatedataylSegment(mspso);

        //优良数量
        Integer ylsize = 0;
        Integer tbylsize = 0;
        Integer hbylsize = 0;
        //有数据总数量
        Integer dataall = 0;
        Integer tbdataall = 0;
        Integer hbdataall = 0;
        if (mapList != null && mapList.size() > 0) {

            //一类水数量
            Integer onesize = 0;
            //二类水数量
            Integer twosize = 0;
            //三类水数量
            Integer threesize = 0;

            for (Map<String, Object> daat : mapList) {
                Object sizesl = daat.get("sizesl");//数量
                Object qualityLevel = daat.get("QualityLevel");//水质级别
                Object qualityLevelName = daat.get("QualityLevelName");
                if (sizesl != null && !"".equals(sizesl)) {
                    if (qualityLevel != null && "0".equals(String.valueOf(qualityLevel))) {

                    } else if (qualityLevel != null && "1".equals(String.valueOf(qualityLevel))) {
                        onesize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "2".equals(String.valueOf(qualityLevel))) {
                        twosize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "3".equals(String.valueOf(qualityLevel))) {
                        threesize = Integer.valueOf(String.valueOf(sizesl));
                    }
                    if (qualityLevel != null && !"0".equals(String.valueOf(qualityLevel))) {
                        dataall = dataall + Integer.valueOf(String.valueOf(sizesl));
                    }
                }
            }
            //数量处理完成后进行数据处理
            ylsize = onesize + twosize + threesize;
        }

        //同比
        mspso.put("SampleDate", tbksData);//最新时间
        //查询同比优良
        List<Map<String, Object>> tbmapList = leaderCockpitMapper.getbasicevaluatedataylSegment(mspso);

        if (tbmapList != null && tbmapList.size() > 0) {
            //一类水数量
            Integer onesize = 0;
            //二类水数量
            Integer twosize = 0;
            //三类水数量
            Integer threesize = 0;

            for (Map<String, Object> daat : tbmapList) {
                Object sizesl = daat.get("sizesl");//数量
                Object qualityLevel = daat.get("QualityLevel");//水质级别
                Object qualityLevelName = daat.get("QualityLevelName");
                if (sizesl != null && !"".equals(sizesl)) {
                    if (qualityLevel != null && "0".equals(String.valueOf(qualityLevel))) {

                    } else if (qualityLevel != null && "1".equals(String.valueOf(qualityLevel))) {
                        onesize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "2".equals(String.valueOf(qualityLevel))) {
                        twosize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "3".equals(String.valueOf(qualityLevel))) {
                        threesize = Integer.valueOf(String.valueOf(sizesl));
                    }
                    if (qualityLevel != null && !"0".equals(String.valueOf(qualityLevel))) {
                        tbdataall = tbdataall + Integer.valueOf(String.valueOf(sizesl));
                    }

                }
            }
            //数量处理完成后进行数据处理
            tbylsize = onesize + twosize + threesize;
        }
        //环比
        mspso.put("SampleDate", hbksData);//最新时间
        //查询达标次数
        List<Map<String, Object>> hbmapList = leaderCockpitMapper.getbasicevaluatedataylSegment(mspso);

        if (hbmapList != null && hbmapList.size() > 0) {
            //一类水数量
            Integer onesize = 0;
            //二类水数量
            Integer twosize = 0;
            //三类水数量
            Integer threesize = 0;
            Integer hbtaall = 0;
            for (Map<String, Object> daat : hbmapList) {
                Object sizesl = daat.get("sizesl");//数量
                Object qualityLevel = daat.get("QualityLevel");//水质级别
                Object qualityLevelName = daat.get("QualityLevelName");
                if (sizesl != null && !"".equals(sizesl)) {
                    if (qualityLevel != null && "0".equals(String.valueOf(qualityLevel))) {

                    } else if (qualityLevel != null && "1".equals(String.valueOf(qualityLevel))) {
                        onesize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "2".equals(String.valueOf(qualityLevel))) {
                        twosize = Integer.valueOf(String.valueOf(sizesl));
                    } else if (qualityLevel != null && "3".equals(String.valueOf(qualityLevel))) {
                        threesize = Integer.valueOf(String.valueOf(sizesl));
                    }
                    if (qualityLevel != null && !"0".equals(String.valueOf(qualityLevel))) {
                        hbdataall = hbdataall + Integer.valueOf(String.valueOf(sizesl));
                    }
                }
            }
            //数量处理完成后进行数据处理
            hbylsize = onesize + twosize + threesize;
        }

        //(达标人数/总人数)×100%
        double IsOverv = 0;
        double hbIsOverv = 0;
        double tbIsOverv = 0;
        if (0 != ylsize) {
            IsOverv = (Double.valueOf(ylsize) / Double.valueOf(dataall)) * 100;
        }
        if (0 != hbylsize) {
            hbIsOverv = (Double.valueOf(hbylsize) / Double.valueOf(hbdataall)) * 100;
        }
        if (0 != tbylsize) {
            tbIsOverv = (Double.valueOf(tbylsize) / Double.valueOf(tbdataall)) * 100;
        }
        List<Map<String, Object>> isoverlist = new ArrayList<>();

        list.put("ylsize", ylsize);
        list.put("tbylsize", tbylsize);
        list.put("hbylsize", hbylsize);
        list.put("yl", df.format(IsOverv));
        list.put("tbyl", df.format(tbIsOverv));
        list.put("hbyl", df.format(hbIsOverv));
        //tbIsOverv-isOver 同/环比 -当前 大于0就是上升 小于0下降
        //上升下降 上升1 下降0 2持平
        double tbv = tbIsOverv - IsOverv;
        double hbv = hbIsOverv - IsOverv;
        if (tbylsize == ylsize) {
            list.put("yltbdataStatus", "2");
            list.put("yltbdataStatusName", "持平");

        } else if (ylsize < tbylsize) {
            list.put("yltbdataStatus", "0");
            list.put("yltbdataStatusName", "下降");

        } else if (ylsize > tbylsize) {
            list.put("yltbdataStatus", "1");
            list.put("yltbdataStatusName", "上升");

        } else {
            list.put("yltbdataStatus", "");
            list.put("yltbdataStatusName", "");
        }

        list.put("yltbdataStatusdata", df.format(tbv));
        if (hbylsize == ylsize) {
            list.put("ylhbdataStatus", "2");
            list.put("ylhbdataStatusName", "持平");
        } else if (ylsize < hbylsize) {
            list.put("ylhbdataStatus", "0");
            list.put("ylhbdataStatusName", "下降");
        } else if (ylsize > hbylsize) {
            list.put("ylhbdataStatus", "1");
            list.put("ylhbdataStatusName", "上升");

        } else {
            list.put("ylhbdataStatus", "");
            list.put("ylhbdataStatusName", "");

        }

        list.put("ylhbdataStatusdata", df.format(hbv));
        list.put("yldataTime", dataTime);
        list.put("ylallSize", size);
        list.put("yltbdataTime", tbksData);
        list.put("ylhbdataTime", hbksData);

        return list;
    }

    public List<Map<String, String>> getWarnRankData() {
        List<Map<String, String>> mapList = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("code", "1");
        map.put("name", "红色");
        mapList.add(map);
        Map<String, String> map2 = new HashMap<>();
        map2.put("code", "2");
        map2.put("name", "橙色");
        mapList.add(map2);
        Map<String, String> map3 = new HashMap<>();
        map3.put("code", "3");
        map3.put("name", "黄色");
        mapList.add(map3);

        return mapList;
    }
}
